import asyncio

from xhs_auto_poster.__001__langgraph_more_nodes.agent_state import AgentState
from xhs_auto_poster.__002__fastapi.msg_queue import msg_queue, MSG_TYPE


async def check_text_image_node(state: AgentState):
    """检查是否可以发布小红书"""
    await msg_queue.put({"type": MSG_TYPE.THINK.name, "content": "开始检测是否发布小红书！"})
    await asyncio.sleep(0.1)
    title = state.get("xhs_tcm_post_title", "")
    content = state.get("xhs_tcm_post_content", "")
    image_path_list = state.get("xhs_tcm_post_image_path", [])
    if not title:
        state["is_publish_xhs"] = False
        state["output"] = "发布小红书失败，标题缺失！"
    if not content:
        state["is_publish_xhs"] = False
        state["output"] = "发布小红书失败，内容缺失！"
    if not image_path_list:
        state["is_publish_xhs"] = False
        state["output"] = "发布小红书失败，图片缺失！"
    state["is_publish_xhs"] = True
    await msg_queue.put({"type": MSG_TYPE.THINK.name, "content": "完成检测是否发布小红书！"})
    await asyncio.sleep(0.1)
    return state
